//
//  Shares.h
//  SolarSeek
//
//  Created by Erick Fejta on 05/01/17.
//  Copyright 2005 Erick Fejta. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@class Peer;

@interface Share : NSObject <NSCoding> {
}

- (NSString *)filenameSharedUnix;

@end

@interface Share (Concrete)
- (NSComparisonResult)compare:(Share *)other;
- (NSString *)filenameShared;
- (unsigned long long)size;
- (NSDictionary *)attributes;
- (NSImage *)icon;
@end

@interface ShareLocal : Share {
	NSString *_filenameLocal;
	unsigned _floor;
}

+ (NSString *)convertFilenameToStyleShared:(NSString *)filename;

- (NSComparisonResult)compare:(ShareLocal *)other;
- (NSString *)filenameLocal;
- (NSString *)filenameSharedUnconverted;
- (unsigned)floorPrivileges;
- (id)initWithFile:(NSString *)file privilege:(unsigned)floor;

@end


@interface SharePeer : Share {
	Peer *_peer;
	NSData *_filenameData;
	NSString *_filenameShared;
	NSDictionary *_attributes;
	NSImage *_icon;
}

- (id)initWithPeer:(Peer *)peer filenameData:(NSData *)filenameShared andAttributes:(NSDictionary *)attributes;

- (NSComparisonResult)compare:(SharePeer *)other;

- (Peer *)peer;
- (NSData *)filenameData;
- (NSData *)dataLastPathComponent;
- (NSData *)dataDeletingLastPathComponent;
- (void)setSize:(unsigned long long)size;
@end

@interface ShareTree : NSObject {
	NSData *_path;
	unsigned startLastComponent;
	NSMutableArray *_subtrees;
	NSMutableArray *_shares;
}

- (id)initWithPathData:(NSData *)path; 

- (unsigned)countSharesThisLevel;
- (unsigned)countSharesThisAndSubLevels;
- (BOOL)isFilledThisLevel;
- (unsigned)countTreesFilledThisAndSubLevels;
- (NSArray *)sharesThisLevel;
- (NSArray *)sharesThisAndSubLevels;
- (NSArray *)subtrees;

- (NSString *)pathComponentLast;
- (NSString *)path;

//- (NSArray *)sharesMatchingString:(NSString *)string;

- (BOOL)addShare:(Share *)sp;
- (void)print;
@end